﻿using AjaxPro;
using Oracle.DataAccess.Client;
using System;
using System.Data;
using System.Web.UI;
using WorkFlow.DBProxy;

namespace WorkFlow.web
{
    /// <summary>
    ///     添加新活动时 增加一组活动库记录
    /// </summary>
    [AjaxNamespace("ns")]
    public partial class AddNewCase : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["USERID"] == null)
            {
                Response.Redirect("login.aspx");
                return;
            }
            Utility.RegisterTypeForAjax(GetType(), Page);
        }

        private int GetUID()
        {
            return int.Parse(Session["USERID"].ToString());
        }

        [AjaxMethod]
        public string Add(string[] strs)
        {
            if (strs.Length != 4 || string.IsNullOrEmpty(strs[0]) || string.IsNullOrEmpty(strs[1]))
                return "你输入错误,请填写完整!";
            int caseid =
                DB.InsertAndGetPK(
                    string.Format(
                        @"insert into t_cases (f_id,f_title,f_content,f_user,f_sex) values(SEQ_CASE.Nextval,'{0}','{1}','{2}','{3}')",
                        strs[0], strs[1], strs[2], strs[3].ToUpper().Equals("M") ? "男" : "女"), "SEQ_CASE");
            OracleParameter[] obj =
            {
                new OracleParameter("caseid", OracleDbType.Int32) {Value = caseid},
                new OracleParameter("var_ownerId", OracleDbType.Int32) {Value = GetUID()},
                new OracleParameter("isSuccessful", OracleDbType.Int32, ParameterDirection.Output)
            };
            DB.ExecuteProc("addAnNewCase", obj);
            return int.Parse(obj[1].Value.ToString().Trim()) > -1 ? "新增案件成功 !" : "新增失败,请检查操作是否正确(--可能是因为没有被流程被激活--) !";
        }
    }
}